﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using UAC;
using UAC.Operation;

namespace UACManager
{
    public partial class TeamRoleDefListForm : Form
    {
        private int teamDefId;
        private TeamDef teamDef;
        public TeamRoleDefListForm(int teamDefId)
        {
            InitializeComponent();
            this.teamDefId = teamDefId;
        }

        private List<TeamRoleDef> teamRoleDefs;
        private void TeamRoleDefListForm_Load(object sender, EventArgs e)
        {
            this.teamDef = Utils.GetTeamDef(this.teamDefId);
            if (this.teamDef == null)
            {
                MessageBox.Show("无效TeamDefId！", "警告");
                return;
            }
            this.tTeamDefID.Text = this.teamDefId.ToString();
            this.tDescription.Text = this.teamDef.Description.ToString();
            this.tTargetDescription.Text = this.teamDef.TargetDescription.ToString();
            LoadTeamRoleDefs();
        }

        private void LoadTeamRoleDefs()
        {
            this.teamRoleDefs = Utils.ListTeamRoleDef(this.teamDefId);
            if (this.teamRoleDefs != null)
            {
                DataTable result = new DataTable();
                result.Columns.Add("TeamRoleDefID");
                result.Columns.Add("TeamDefID");
                result.Columns.Add("Name");
                result.Columns.Add("Description");
                result.Columns.Add("Status");

                foreach (TeamRoleDef teamRoleDef in this.teamRoleDefs)
                {
                    DataRow dr = result.NewRow();
                    dr[0] = teamRoleDef.TeamRoleDefID;
                    dr[1] = teamRoleDef.TeamDefID;
                    dr[2] = teamRoleDef.Name;
                    dr[3] = teamRoleDef.Description;
                    dr[4] = teamRoleDef.Status;
                    result.Rows.Add(dr);
                }
                this.dataGridViewMain.DataSource = result;
            }
        }

        private void btnAdd_Click(object sender, EventArgs e)
        {
            using (TeamRoleDefForm trdf = new TeamRoleDefForm(this.teamDefId))
            {
                if (trdf.ShowDialog() == System.Windows.Forms.DialogResult.OK)
                {
                    LoadTeamRoleDefs();
                }
            }
        }
    }
}
